package com.nulldev.util.java.extendedUI.fontAPI;

import java.awt.Font;

import javax.swing.JPanel;

/**
 * The smart font manager for Java Swing, AWT and FX. <br>
 * Designed for the cSwing API.
 * @author null
 * @since nullUtil 2.7
 */
public class FontAPI {

	public static class DefaultFonts {
		private static final JPanel __reference_font_panel = new JPanel();
		private static final Font __font = __reference_font_panel.getFont();
		
		/**
		 * Attempts to load the default font. (by peforming a double static call) <br>
		 * Throws errors on: <br>
		 * - Headless Swing <br>
		 * - Panel creation errors <br>
		 * - Gay frogs. <br>
		 */
		public static void checkDefaultFontLoad() {
			__reference_font_panel.isVisible();
			if (__reference_font_panel == null) {
				throw new RuntimeException("FontAPI.DefaultFonts: Source for default fonts came out to be false!");
			}
		}
		
		/**
		 * Returns standard font. <br>
		 * WARNING: This font may not be visible, <code>deriveFont(float size)</code> may have to be used.
		 * @returns Font 
		 */
		public static Font _defaultFont() {
			checkDefaultFontLoad();
			return __font;
		}
		
		/**
		 * Unlike <code>_defaultFont()</code>, this returns a visible font that does not default to the size of '1'.
		 * @returns Size 16 default Java Font.
		 */
		public static Font defaultFont() {
			return _defaultFont().deriveFont(16f);
		}
		
		public static Font defaultFont(final int size) {
			return _defaultFont().deriveFont((float) size);
		}
		
		public static Font defaultFont(final float size) {
			return _defaultFont().deriveFont((float) size);
		}
	}
}
